package com.itheima.cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
构建一个非会话级别的cookie
 */
@WebServlet("/life")
public class LifeCookieServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("构建一个cookie,它的存活时间 持久话级别");
        //如何构建cookie
        Cookie cookie = new Cookie("heima", "java");

        System.out.println("改变该cookie的存活时间  让它保留一天时间 ");
        //调用  setMaxAge（秒）
        cookie.setMaxAge(60*60*24);
        response.addCookie(cookie);


        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write("存活一天的cookie已经有了，自己去查看");
    }
}
